package 剑指offer;

/**
 * @description:
 * @author: ywk
 * @date: 2020-07-27
 */
public class 求n次方 {
    public static void main(String[] args) {
        System.out.println(rec(2, 3));
    }

    public  static int rec(int a, int n) {
        if (n == 1) {
            return a;
        }
        if (n % 2 == 1) {
            return rec(a, n - 1) * a;
        }
        return rec(a, n / 2) * rec(a, n / 2);
    }
}
